package com.cskaoyan.util.common;

/**
 * @program: market
 * @description: 对字符串进行校验、修正
 * @author: zhong
 * @create: 2022-07-17 14:51
 **/
public class StringUtils {
    public static boolean isEmpty(String str) {
        if (str == null || "".equals(str.trim())) {
            return true;
        }
        return false;
    }

    public static boolean isInvalid(String str) {
        if (isEmpty(str) || "[]".equals(str.trim())) {
            return true;
        }
        return false;
    }

    //用于分割json数组
    public static String[] splitJsonArrays(String jsonStr) {
        if (isInvalid(jsonStr)) {
            return new String[0];
        }

        return jsonStr.substring(1, jsonStr.length() - 1).replaceAll("\"","").split(",");
    }

    public static Integer[] splitJsonToIntArrays(String jsonStr) {
        String[] splitStr = splitJsonArrays(jsonStr);
        Integer[] intArr = new Integer[splitStr.length];
        for (int i = 0; i < splitStr.length; i++) {
            intArr[i] = Integer.parseInt(splitStr[i]);
        }
        return intArr;
    }


    private StringUtils() {
    }
}
